<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title></title>
    <link rel="stylesheet" type="text/css" href="../../css/aui.css" />
    <link rel="stylesheet" type="text/css" href="../../css/aui-pull-refresh.css" />
</head>

<body>
    <section class="aui-refresh-content" id="pContainer1">
        <div class="aui-content">
            <ul class="aui-list aui-list-in" tapmode id="list">
                <script id="listTemplate" type="text/x-dot-template">
                {{? it.type===0 }}

                    {{for(var i=0;i<it.list.length;i++){}}
                    <li class="aui-list-item aui-list-item-middle" tapmode data-url='{{="http://"+it.list[i].picOssUrl.split(":")[1].replace(",", "/")}}' onclick="showImg(this)">
                        <div class="aui-list-item-inner aui-list-item-arrow" style="font-size: 0.9rem;">
                            <b>{{=("http://"+it.list[i].picOssUrl.split(":")[1].replace(",", "/")).replace(/(.*\/)*([^.]+).*/ig,"$2")}}</b>
                            </li>
                            {{}}}
                            {{??}}
                            {{for(var i=0;i<it.list.length;i++){}}
                            <li class="aui-list-item aui-list-item-middle" tapmode data-url='{{="http://"+it.list[i].proveImgUrl.split(":")[1].replace(",", "/")}}' onclick="showImg(this)">
                                <div class="aui-list-item-inner aui-list-item-arrow" style="font-size: 0.9rem;">
                                    <b>{{=it.list[i].proveImgName}}</b>
                                    </li>
                                    {{}}}
                            {{?}}
                </script>
            </ul>
            </div>
    </section>
</body>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/doT.js"></script>
<script type="text/javascript" src="../../script/util.js"></script>
<script type="text/javascript" src="../../script/aui-pull-refresh.js"></script>
<script type="text/javascript">
    var pageNumber = 1;
    var pid;
    var pv;
    apiready = function() {
        api.parseTapmode();
        // 老人编号
        pid = api.pageParam.id;
        pv = api.require('UIPhotoViewer');
        loadData(pageNumber,api.pageParam.type);
    };
    var pullRefresh = new auiPullToRefresh({
        container: document.querySelector('.aui-refresh-content'),
        triggerDistance: 100
    }, function(ret) {
        console.log("下拉刷新：" + JSON.stringify(ret));
        if (ret.status === "success") {
            loadData(++pageNumber,api.pageParam.type);
        }
    });

    function loadData(pageNumber,type) {
        //pContainer1.style.marginTop = "20px";
        console.log("type:"+type);
        console.log("token:"+$api.getStorage('userinfo').token);
        var url = '';
        if (type==0) {
          url = base + 'gero/api/olderFile/pagingQuery';
        }else {
          url = base + 'gero/api/sdm/oos/hukou/pagingQuery';
        }
        api.showProgress({});
        api.ajax({
            url: url,
            method: 'post',
            data: {
                values: {
                    token: $api.getStorage('userinfo').token,
                    pageNo: pageNumber,
                    pageSize: '20',
                    olderId: pid
                }
            }
        }, function(ret, err) {

            if (ret && ret.code == "200") {
                var template = $api.byId('listTemplate');
                var list_content = $api.byId('list');
                var pagefn = doT.template(template.text);
                ret.type = type;
                list_content.insertAdjacentHTML('afterbegin', pagefn(ret));
                pullRefresh.cancelLoading();
                console.log('ret：' + JSON.stringify(ret));
                if (ret.count === 0) {
                    tips('没有附件信息，请上传后查阅。');
                }
            } else {
                doLogin();
            }
            api.hideProgress();
        });
    }
    // 显示图片
    function showImg(url) {
      console.log($api.attr(url, 'data-url'));

        pv.open({
            images: [
                $api.attr(url, 'data-url')
            ],
            placeholderImg: 'widget://icon/icon.png',
            bgColor: '#000'
        }, function(ret, err) {
            if (ret && ret.eventType==="click") {
                pv.close();
            }
        });
    }
</script>

</html>
